#pragma once
#ifndef DICTIONARY_H_
#define DICTIONARY_H_
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <time.h>
#include <assert.h>
#include <stdlib.h>
#include <iomanip>
#include "htable.h"
using namespace std;

#define DICTIONARY_LOAD_FACTOR_1  2.0

#ifndef GROWTH_STEP_1
#define GROWTH_STEP_1 1.5
#endif

class strstack;

struct dict_entry {
	const char *word;
	unsigned int code;
	unsigned long long freq;
};

class dictionary
{
private:
	strstack *st;

	dict_entry *dictTable; //!< number of dict entry
	htable<char*> *htbDict;
	unsigned int totalEntry;
	unsigned int limSizeDict;

public:
	dictionary(void);
	dictionary(const string &inputFilename);
	~dictionary(void);

	void grow();
	void tokenize(const string& str, const char& delimiter, vector<string>& tokens);

	void generate(const string &inputFilename);
	void load(const string &inputFilename);

	bool findEntry(const string &entry);
	char* operator[](unsigned int index) const;
	unsigned int size();

	unsigned int* encode(const string &entry) const;
	unsigned int* encode(char* entry) const;

	void save(const string &outputFilename);
	void save(const string &outputFilename, const int &thresholdFreq);

	void stat(const string &outputFilename);
};

#endif
